package com.andy.blog.admin.service.impl;

import com.andy.blog.admin.dto.TalkDTO;
import com.andy.blog.admin.service.TalkBusService;
import com.andy.blog.common.page.PageUtilsDTO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by andy on 2023/10/15 17:08
 */
@Service
public class TalkBusServiceImpl implements TalkBusService {
    @Override
    public PageUtilsDTO<TalkDTO> listTalkVO() {
        // 查询说说总量
        //Long count = talkMapper.selectCount((new LambdaQueryWrapper<Talk>()
        //        .eq(Talk::getStatus, PUBLIC.getStatus())));
        //if (count == 0) {
        //    return new PageResult<>();
        //}
        // 分页查询说说
        //List<TalkDTO> talkVOList = talkMapper.selectTalkList(PageUtils.getLimit(), PageUtils.getSize());
        // 查询说说评论量
        //List<Integer> talkIdList = talkVOList.stream()
        //        .map(TalkVO::getId)
        //        .collect(Collectors.toList());
        //List<CommentCountVO> commentCountVOList = commentMapper.selectCommentCountByTypeId(talkIdList, TALK.getType());
        //Map<Integer, Integer> commentCountMap = commentCountVOList.stream()
        //        .collect(Collectors.toMap(CommentCountVO::getId, CommentCountVO::getCommentCount));
        // 查询说说点赞量
        //Map<String, Integer> likeCountMap = redisService.getHashAll(TALK_LIKE_COUNT);
        // 封装说说
        //talkVOList.forEach(item -> {
        //    item.setLikeCount(Optional.ofNullable(likeCountMap.get(item.getId().toString())).orElse(0));
        //    item.setCommentCount(Optional.ofNullable(commentCountMap.get(item.getId())).orElse(0));
        //    // 转换图片格式
        //    if (Objects.nonNull(item.getImages())) {
        //        item.setImgList(CommonUtils.castList(JSON.parseObject(item.getImages(), List.class), String.class));
        //    }
        //});
        List<TalkDTO> talkVOList = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            TalkDTO talkDTO = new TalkDTO();
            talkDTO.setId((long) i);
            talkDTO.setNickname("昵称" + i);
            talkDTO.setAvatar("http://s1qmuvqoq.bkt.clouddn.com/20230929/%E6%B8%B8%E5%AE%A2%E5%A4%B4%E5%83%8F.jpeg");
            talkDTO.setTalkContent("我是说说" + i);
            talkDTO.setImages("imasges");
            talkDTO.setIsTop(1);
            talkDTO.setLikeCount(2);
            talkDTO.setCommentCount(1);
            talkDTO.setCreateTime(new Date());
            talkVOList.add(talkDTO);
        }

        //talkVOList.forEach(item -> {
            // 转换图片格式
            //if (Objects.nonNull(item.getImages())) {
            //    item.setImgList(CommonUtils.castList(JSON.parseObject(item.getImages(), List.class), String.class));
            //}
        //});
        return PageUtilsDTO.build(10L, talkVOList);
    }
}
